package com.example.parition;

import org.apache.flink.api.common.functions.FlatMapFunction;
import org.apache.flink.api.common.typeinfo.Types;
import org.apache.flink.api.java.functions.KeySelector;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.KeyedStream;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.util.Collector;

/**
 * Created with IntelliJ IDEA.
 * ClassName: WordCountStream
 * Package: com.example.wordcount
 * Description:
 * User: fzykd
 *
 * @Author: LQH
 * Date: 2023-07-17
 * Time: 10:52
 */

//流处理 读文件
//流处理 wordCount案例
public class PartitionDemo {
    public static void main(String[] args) throws Exception {
        //1.创建执行环境
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        env.setParallelism(2);

        //2.读取数据 从socket读
        DataStreamSource<String> hadoop102 = env.socketTextStream("hadoop102", 7777);

        //随机分区
        //hadoop102.shuffle().print();


        //轮询分区Round-Robin 用于处理数据源的倾斜
        //hadoop102.rebalance().print();

        //缩放 局部轮询
        //hadoop102.rescale().print();

        //广播 每个分区都发送数据
        //hadoop102.broadcast().print();

        //全部发网同一个分区器
        hadoop102.global().print();

        //keyby也算一个分区 相同的key去同一个子任务
        //总结 7中分区器 + 一个自定义 8种

        env.execute();
    }
}
